#星号表达式在迭代元素为可变长元祖的序列时是很有用的
records = [
    ('foo', 1, 2),
    ('bar', 'hello'),
    ('foo', 3, 4)
]

def do_foo(x, y):
    print('foo', x, y)

def do_bar(s):
    print('bar', s)

def demo_1():
    for tag, *args in records:
        if tag == 'foo':
            do_foo(*args)
        elif tag == 'bar':
            do_bar(*args)

def demo_2():
    line = 'nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false'
    uname, *fields, homedir, sh = line.split(':')
    print('{}, {}, {}, {}'.format(uname, fields, homedir, sh))
    record = ('ACME', 50, 123.45, (12, 18, 2012))
    name, *_, (*_, year) = record
    print("{}, {}".format(name, year))

if __name__ == '__main__':
    demo_1()
    demo_2()